package com.aion.jirc.gui;

import javax.swing.JButton;
import javax.swing.JSeparator;
import javax.swing.JToolBar;
import javax.swing.SwingConstants;
import java.awt.Component;
import java.awt.event.ActionListener;

/**
 * Created by IntelliJ IDEA.
 * User: Aion
 * Date: 11-02-19
 * Time: 11:40
 */
public class Toolbar extends JToolBar {

    private ActionListener listener;

    private static final String[] BUTTONS;

    static {
        BUTTONS = new String[]{"Connect", "Disconnect", "-", "Join", "Part"};
    }

    protected Toolbar(ActionListener listener) {
        super();
        this.listener = listener;
        for (int i = 0; i < BUTTONS.length; i++) {
            add(constructToolbar(BUTTONS[i]));
        }
    }

    private Component constructToolbar(String item) {
        JButton button = new JButton(item);
        if (item.equals("-")) {
            button.setEnabled(false);
        }
        button.setActionCommand("Toolbar." + item);
        button.addActionListener(listener);
        return button;
    }
}
